﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Xml;
using System.Xml.Xsl;
using Ext.Net;

public partial class AddEstate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {       
        
    }

    protected void CitiesRefresh(object sender, StoreRefreshDataEventArgs e)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(HttpContext.Current.Server.MapPath("Cities.xml"));
        List<object> data = new List<object>();

        foreach (XmlNode cityNode in xmlDoc.SelectNodes(string.Concat("countries/country[@code='", this.Countries.SelectedItem.Value, "']/city")))
        {
            string id = cityNode.SelectSingleNode("id").InnerText;
            string name = cityNode.SelectSingleNode("name").InnerText;

            data.Add(new { Id = id, Name = name });
        }
        this.CitiesStore.DataSource = data;

        this.CitiesStore.DataBind();
    }

    [DirectMethod]
    public void addEstate()
    {        
        SqlConnection myConnection;
        SqlCommand myCommand;
        //SqlDataReader myDataReader;

        string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["SiyahBayrakConnectionString"].ConnectionString;

        myConnection = new SqlConnection(strConn);
        myConnection.Open();
        myCommand = new SqlCommand("addEstate", myConnection);
        myCommand.CommandType = System.Data.CommandType.StoredProcedure;

        DateTime createDate;
        createDate = DateTime.Now;

        myCommand.Parameters.AddWithValue("@roomCount", room.Text);
        myCommand.Parameters.AddWithValue("@isSale", MenuPanel6.HeaderAsText);
        myCommand.Parameters.AddWithValue("@price", price.Text);
        myCommand.Parameters.AddWithValue("@typeof", "1");
        myCommand.Parameters.AddWithValue("@subType", "1");
        myCommand.Parameters.AddWithValue("@city", Countries.Text);
        myCommand.Parameters.AddWithValue("@town", Cities.Text);
        myCommand.Parameters.AddWithValue("@district", "1");
        myCommand.Parameters.AddWithValue("@m2", m2.Text);
        myCommand.Parameters.AddWithValue("@title", title.Text);
        myCommand.Parameters.AddWithValue("@descrip", descrip.Text);
        myCommand.Parameters.AddWithValue("@createDate", createDate);
        myCommand.Parameters.AddWithValue("@usersId", "1");
        myCommand.Parameters.AddWithValue("@ownerClientId", "1");        

        myCommand.ExecuteNonQuery();
        gorkem.Text = "Kaydınız Eklenmiştir.";
        Button1.Visible = false;

    }    
}